<template>
  <tl-sub-page :render="render" :visible.sync="dialogVisible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" :fullscreen="true" append-to-body @close="close">
    <el-collapse v-model="activeNames">
      <el-collapse-item name="1">
        <template slot="title">
          <div class="tl-form-line-title sub-title" style="height: auto;width: 100%;line-height: 28px;">
            <span style="float:left">{{title}}</span>
          </div>
        </template>
        <el-form class="tl-form" ref="form" :model="model" label-width="90px" :disabled="!editable">
          <el-row>
            <el-col :span="6">
              <el-form-item label="目标得分" prop="targetscore">
                <el-input v-model="model.targetscore"  oninput="this.value=this.value.match(/\d{0,}\.?\d{0,1}/)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="showgapanalysis">
              <el-form-item label="实际得分" prop="completionscore" >
                <el-input v-model="model.completionscore"  oninput="this.value=this.value.match(/\d{0,}\.?\d{0,1}/)"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" v-if="showgapanalysis">
              <el-form-item label="差距分析" prop="gapanalysis">
                <el-input type="textarea" rows="2" v-model="model.gapanalysis" maxlength="1000" show-word-limit></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-collapse-item>
    </el-collapse>
  </tl-sub-page>
</template>

<script>
  /** mixins */
  import { mixin_list } from '@tapui/mixins/mixin_list'
  /** 工具类 */
  import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
  import { checkPermission } from '@tapui/utils/permission'
  export default {
    name: 'mpmProjectBidScore',
    mixins: [mixin_list],
    components: { },
    data() {
      return {
        description: '评标细则信息表-列表查询',
        urlPrefix: '/mpm/projectBidScore/',
        url: {
          queryCodeList: '/mpm/projectBidScore/dataCodeList',
          fullScoreInfo: '/mpm/projectBidFullScore/fullScoreInfo',
          update: '/mpm/projectBidScore/update',
          insert: '/mpm/projectBidScore/insert'
        },
        // 排序参数
        model: {},
        activeNames: ['1'],
        dialogVisible: false
      }
    },
    props: {
      projectinfo: {},
      title: {
        type: [String],
        default: ''
      },
      times: {
        type: [String],
        default: '1'
      },
      type: {
        type: [String],
        default: '1'
      },
      editable: {
        type: Boolean,
        default: false
      },
      render: {
        default: 'div',
        type: String
      },
      showgapanalysis: {
        type: Boolean,
        default: false
      }
    },
    computed: {
    },
    methods: {
      close() {
        this.$emit('refresh')
      },
      fullScoreInfo() {
        if (!this.projectinfo) {
          return false
        }
        return getAction(this.url.fullScoreInfo, { times: this.times, type: this.type, projectcode: this.projectinfo.projectcode }).then((res) => {
          if (res.success) {
            if (!res.result.totalfullscore || res.result.totalfullscore === '') {
              this.totalfullscore = '100'
            } else {
              this.totalfullscore = res.result.totalfullscore
            }
            this.$emit("getFullScoreInfo", res.result)
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
      },
      beforeLoadData() {
        this.fullScoreInfo()
        if (!this.projectinfo || !this.projectinfo.projectcode) {
          return false
        }
        this.queryParam.qry_projectcode = this.projectinfo.projectcode
        this.queryParam.qry_type = this.type
        this.queryParam.qry_times = this.times
        return true
      },
      /** 加载数据之后 */
      afterLoadData() {
        if (this.datas && this.datas.length > 0) {
          this.model = this.datas[0]
        }
      },
      async doSave() {
        if (this.model.id) {
          await putAction(this.url.update, this.model).catch((err) => {
            this.saveLoading = false
          })
        } else {
          this.model.times = this.times
          this.model.type = this.type
          this.model.projectcode = this.projectinfo.projectcode
          this.model.state = 9
          let result = await postAction(this.url.insert, this.model).catch((err) => {
            this.saveLoading = false
          })
          if (result.success) {
            this.model = result.result
          }
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  $small:600px;
  $medium:1380px;

  .statistic-title {
    float:right;
    @media screen and (max-width:$medium) {
      font-size: 16px;
    }
  }
  .score-title {
    float:left;
    margin-left: 10px;
    width: 223px;
  }
  .text-hover:hover {
    color: #0A6ED2;
    cursor: pointer;
    font-weight: bold;
  }
</style>

